//
// Created by v on 19-2-22.
//

#include <malloc.h>
#include <stdio.h>
#include <unistd.h>

#include "cm_avprocess.h"
#include "utils/rt_print.h"

void avprocess_test()
{
    CMAVProcessP av;
    cm_avprocess_init(&av);

    cm_avprocess_av_ready(av, 640, 480);

    FILE *         f    = fopen("/opt/data/output/1-yuv420.yuv", "r");
    int            len  = 640 * 480 * 3 / 2;
    unsigned char *data = (unsigned char *)malloc(len);
    if (f)
    {
        int frames = 0;
        while (1)
        {
            int ret = fread(data, 1, len, f);
            if (ret <= 0)
            {
                if (ret == 0)
                {
                    rtinfo("read done\n");
                }
                else
                {
                    rterror("read error %d\n", ret);
                }
                break;
            }
            cm_avprocess_write(av, data, len);
            rtinfo("process write frames %d\n", frames++);
        }

        fclose(f);
    }
    else
    {
        rterror("file open failed\n");
    }

    cm_avprocess_deinit(&av);
}

int main(int argc, char **args)
{
    rt_print_init(RT_PRINT_ALL, RT_PRINT_STYLE_ALL, RT_COLOR_TRUE, "avprocess");
    avprocess_test();
    return 0;
}